<%@page import="java.io.*,
java.util.*,java.util.Date,java.text.DateFormat,java.text.SimpleDateFormat,
java.io.FileReader,
java.io.BufferedReader,
javax.persistence.EntityManager,
javax.persistence.EntityManagerFactory,
javax.persistence.EntityTransaction,
javax.persistence.Persistence,
javax.persistence.Query,
model.User,
java.sql.Connection,
java.sql.DriverManager,
java.sql.SQLException,
java.sql.PreparedStatement
"%>
<%! Connection cn = null;  %>
<%! public String p = null; %><% if(request.getParameter("p") != null) {  p = request.getParameter("p"); } %>
<%! public int q = 1; %><% if(request.getParameter("q") != null) {  q = Integer.parseInt(request.getParameter("q")); } %>

<%
try {
//addQuestion("it","Which of the Following is an Operating System","Linux","Word","Excel","Power Point","Access",1);
System.out.println("record added");
} catch(Exception e1) { System.out.println(e1); }
	
	try { 
	///Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
	cn = DriverManager.getConnection("jdbc:derby:db;create=false;user=admin;password=13131");
	System.out.println("Connected to Embedded Java DB!");
	///cn = DriverManager.getConnection("jdbc:derby:db;create=false;user=admin;password=13131");
	
	// variables
//	private static String dbURL = "jdbc:derby:db;create=false;user=admin;password=13131";

	
	} catch(SQLException e) { System.out.println("duba "+e);}

%>



<%! public String frontpage() {
	String out = "";
	
	out = "<h2 class='title'><a href='#'>Welcome Please Select Quiz Category to Start</a></h2>"+
			"<div id='frontimage'><table width='100%' border='0' cellspacing='0' cellpadding='0'><tr align='center'> "+
			"<td><a href='?p=it'><img src='images/it.png' alt='' width='200' height='150' /></a></td> "+
			"<td><a href='?p=lr'><img src='images/Bad-LSAT-Arguments-300x212.png' alt='' width='200' height='150' /></a></td> "+
			"<td><a href='?p=gk'><img src='images/PlagiarismThe-LSAT_03.png' alt='' width='200' height='150' /></a></td></tr><tr> "+
			"<td align='center'><a href='?p=it'>Information Technology</a></td><td align='center'><a href='?p=lr'>Logical Reason</a></td><td align='center'><a href='?p=gk'>General Knowledge</a></td></tr></table> "+
			"<a href='/#'><img src='images/quiz.gif' alt='Picture 1' width='300' height='200' /></a><a href='/#'><img src='images/Books-icon.png' alt='Picture 1' width='300' height='200' /></a> "+
			"</div><div class='content' align='center'>Current Date time: Fri Jun 21 14:04:44 UTC 2013</div>";
	
	
	return out;
}
%>

<%! public String aboutus() {
	String out = "";
	
	out = "<h2 class='title'><a href='#'>About Us</a></h2>";
	
	
	return out;
}
%>

<%! public String it() {
	String out = "";
	
	out = "<h2 class='title'><a href='#'>Welcome to Information Technology Quesions</a></h2>";
	
	
	
	
	
	return out;
}
%>

<%! public String q(int no) {
	String out = "";
	

	out +="<table><tr><th>Quesion "+no+"</th></tr>";
	out +="<tr><td>Q1. Which of the Following is Computer Hardware?</td></tr>";
	out +="<tr><td><input type='checkbox' name='vehicle' value='Bike'> A. Microsoft Office Word<br></td></tr>";
	out +="<tr><td><input type='checkbox' name='vehicle' value='Bike'> B. Microsoft Windows XP<br></td></tr>";
	out +="<tr><td><input type='checkbox' name='vehicle' value='Bike'> C. Computer Webcam<br></td></tr>";
	out +="<tr><td><input type='checkbox' name='vehicle' value='Bike'> D. Computer Webcam<br></td></tr>";
	out +="<tr><td><input type='checkbox' name='vehicle' value='Bike'> E. Computer Webcam<br></td></tr>";
	out +="<tr><td><input type='submit' name='submit' value='Submit'></td></tr>";
	
	
	
	
	out +="</table>";
	
	
	return out;
}
%>

<%! public void addQuestion(String type, String question, String op1, String op2, String op3, String op4, String op5, int ans) throws SQLException {
		PreparedStatement ps = null;
	 
	String insertTableSQL = "INSERT INTO QUESTIONS"
			+ "(QTYPE, QUESTION, OP1, OP2, OP3, OP4, OP5, ANSWER) VALUES"
			+ "(?,?,?,?,?,?,?,?)";

	try {
		ps = cn.prepareStatement(insertTableSQL);

		//ps.setInt(1, 11);
		ps.setString(1, type);
		ps.setString(2, question);
		ps.setString(3, op1);
		ps.setString(4, op2);
		ps.setString(5, op3);
		ps.setString(6, op4);
		ps.setString(7, op5);
		ps.setInt(8, ans);
		//ps.setTimestamp(4, getCurrentTimeStamp());

		// execute insert SQL stetement
		ps.executeUpdate();

		System.out.println("Record is inserted into QUESTIONS table!");

	} catch (SQLException e) {

		System.out.println(e.getMessage());

	} finally {

		if (ps != null) {
			ps.close();
		}

		if (cn != null) {
			cn.close();
		}

	}

	
	
	
	
}


%>

<%! public String addquestion() {
	String out = "";

	out +="<h2 class='title'>Add new Question to Database</h2><form name='signupform' id='signupform' method='post' action=''><fieldset> "+
		"<label>Quetion Category</label><select name='qtype' id='qtype'><option value='it' selected='selected'>Information Technology</option> "+
		"<option value='lr'>Logical Reason</option><option value='gk'>General Knowledge</option></select><br> "+
		"<label>Question</label><input type='text' id='op1' name='op1'> "+
		"<label>Option 1</label><input type='text' id='op2' name='op2'> "+
		"<label>Option 2</label><input type='text' id='op3' name='op3'> "+
		"<label>Option 3</label><input type='text' id='op4' name='op4'> "+
		"<label>Option 4</label><input type='text' id='op5' name='op5'> "+
		"<br></br><input type='submit' name='submit' id='addq' value='Add to Database' class='form-submit'></fieldset></form>";	
	
	return out;
}
%>

<%! public String sidebar2() {
	String out = "";
	
	out = "<div class='block block-user' id='block-user-3'><h2 class='title' align='center'>Latest quiz</h2><a href='/#'> "+
		"<img src='images/quiz_icon.png' alt='Picture 1' width='200' height='200'></a><div class='content' align='center'> "+
		"Test your brain<a href='/#'><img src='images/icon_256.png' alt='Picture 1' width='200' height='200'></a></div></div>";
	return out;
}
%>

<%! public String usermenu() {
	String out = "";
	
	out = "<div class='block block-user' id='block-user-3'><h2 class='title' align='center'>User Menu</h2>"+
		"<h2>Information Technology</h2>"+
		"";
	return out;
}
%>



